/**
 * 
 */
package com.arx.interactive;

import com.dalonedrau.pool.PooledStringBuilder;
import com.dalonedrau.pool.StringBuilderPool;

/**
 * @author Donald
 */
public class InteractiveIORetrievalBase extends InteractiveIOManipulationBase {
	/**
	 * Gets the index number of a registered interactive item.
	 * @param io the {@link InteractiveObject}
	 * @return int
	 */
	public final int getInterNum(final InteractiveObject io) {
		int num = -1;
		if (io != null) {
			for (int i = 0; i < super.getNbmax(); i++) {
				if (io.equals(super.getInteractiveObject(i))) {
					num = i;
					break;
				}
			}
		}
		return num;
	}
	/**
	 * Finds IO number by name.
	 * @param name
	 * @return
	 */
	@Override
	public final int GetTargetByNameTarget(final String name) {
		String temp;
		int val = -1;
		if (name != null) {
			if (name.equalsIgnoreCase("player")) {
				// player is now an io with index 0
				val = 0;
			} else if (name.equalsIgnoreCase("none")) {
				val = -1;
			} else if (name.equalsIgnoreCase("self")
					|| name.equalsIgnoreCase("me")) {
				val = -2;
			} else {

				for (int i = 0; i < super.getNbmax(); i++) {
					if (super.getInteractiveObject(i) != null
							&& super.getInteractiveObject(i).getIdent() > -1) {
						PooledStringBuilder sb = StringBuilderPool
								.getInstance()
								.getStringBuilder();
						sb.append(super.getInteractiveObject(i).getFilename());
						sb.append("_");
						sb.append(String.format("%04d",
								super.getInteractiveObject(i).getIdent()));
						temp = sb.toString();
						// sprintf(temp, "%s_%04d",
						// GetName(inter.iobj[i]->filename),
						// inter.iobj[i]->ident);
						if (temp.equalsIgnoreCase(name)) {
							return i;
						}
					}
				}
			}
		}
		return val;
	}
}
